package com.meloneatingmasses.lowcodeplatform.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.meloneatingmasses.lowcodeplatform.po.ContentJson;
import com.meloneatingmasses.lowcodeplatform.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content")
public class ContentController {


    @Autowired
    private ContentService contentService;

    @CrossOrigin
    @PostMapping("/save")
    public String save(@RequestBody JSONObject json){
        System.out.println(json);
        ContentJson contentJson = new ContentJson();
        contentJson.setResultJson(json);
        ContentJson coll = contentService.insert(contentJson);
        return coll.getId();
    }

    @CrossOrigin
    @GetMapping("/get")
    public ContentJson getById(String id) {
        ContentJson contents = contentService.getContents(id);
        return contents;
    }
}
